import { Router } from 'express';
import { NotificationController } from '../../api/controllers/notificationController';
import { authenticateClient } from '../../middleware/auth';
import { logOperation } from '../../middleware/operationLog';

const router = Router();
const notificationController = new NotificationController();

/**
 * @swagger
 * /api/client/notifications:
 *   get:
 *     summary: 获取用户通知列表
 *     tags: [Notifications]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 20
 *         description: 每页数量
 *       - in: query
 *         name: type
 *         schema:
 *           type: string
 *           enum: [PERFORMANCE, VOTE, SYSTEM, PROMOTION]
 *         description: 通知类型
 *     responses:
 *       200:
 *         description: 成功获取通知列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取通知列表成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     notifications:
 *                       type: array
 *                       items:
 *                         $ref: '#/components/schemas/Notification'
 *                     pagination:
 *                       $ref: '#/components/schemas/Pagination'
 *                     unreadCount:
 *                       type: integer
 *                       description: 未读通知数量
 */
router.get('/', authenticateClient, logOperation('list', 'notification'), notificationController.getNotifications);

/**
 * @swagger
 * /api/client/notifications/{id}/read:
 *   put:
 *     summary: 标记通知为已读
 *     tags: [Notifications]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 通知ID
 *     responses:
 *       200:
 *         description: 成功标记已读
 */
router.put('/:id/read', authenticateClient, logOperation('update', 'notification'), notificationController.markAsRead);

/**
 * @swagger
 * /api/client/notifications/read-all:
 *   put:
 *     summary: 标记所有通知为已读
 *     tags: [Notifications]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 成功标记所有通知为已读
 */
router.put('/read-all', authenticateClient, logOperation('update', 'notification'), notificationController.markAllAsRead);

/**
 * @swagger
 * /api/client/notifications/unread-count:
 *   get:
 *     summary: 获取未读通知数量
 *     tags: [Notifications]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 成功获取未读通知数量
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取未读通知数量成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     count:
 *                       type: integer
 *                       description: 未读通知数量
 */
router.get('/unread-count', authenticateClient, notificationController.getUnreadCount);

/**
 * @swagger
 * /api/client/notifications/{id}:
 *   delete:
 *     summary: 删除通知
 *     tags: [Notifications]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 通知ID
 *     responses:
 *       200:
 *         description: 成功删除通知
 */
router.delete('/:id', authenticateClient, logOperation('delete', 'notification'), notificationController.deleteNotification);

/**
 * @swagger
 * /api/client/user/notification-settings:
 *   get:
 *     summary: 获取用户通知设置
 *     tags: [Notifications]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 成功获取通知设置
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取通知设置成功
 *                 data:
 *                   $ref: '#/components/schemas/UserNotificationSettings'
 */
router.get('/user/notification-settings', authenticateClient, notificationController.getNotificationSettings);

/**
 * @swagger
 * /api/client/user/notification-settings:
 *   put:
 *     summary: 更新用户通知设置
 *     tags: [Notifications]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               pushEnabled:
 *                 type: boolean
 *                 description: 是否启用推送通知
 *               emailEnabled:
 *                 type: boolean
 *                 description: 是否启用邮件通知
 *               performanceReminder:
 *                 type: boolean
 *                 description: 是否启用演出提醒
 *               voteReminder:
 *                 type: boolean
 *                 description: 是否启用投票提醒
 *     responses:
 *       200:
 *         description: 成功更新通知设置
 */
router.put('/user/notification-settings', authenticateClient, logOperation('update', 'notification_settings'), notificationController.updateNotificationSettings);

export default router; 